﻿using Naruto.TaskManagement.Entitys.DTO;
using Naruto.TaskManagement.Infrastructure;
using Naruto.TaskManagement.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Naruto.TaskManagement.Application
{
    /// <summary>
    /// 聊天消息
    /// </summary>
    public class ChatMessageApps : IApp
    {
        private readonly IChatMessageRepository chatMessageRepository;
        private readonly ITaskManageUnitOfWork unitOfWork;

        public ChatMessageApps(IChatMessageRepository _chatMessageRepository, ITaskManageUnitOfWork _unitOfWork)
        {
            chatMessageRepository = _chatMessageRepository;
            unitOfWork = _unitOfWork;
        }

        /// <summary>
        /// 获取我的聊天消息记录
        /// </summary>
        public async Task<NarutoResult> MyChatMessage(MyChatMessageDTO info)
        {
            if (info.UserId .IsNullEmpty())
            {
                return new NarutoFailResult("参数错误.");
            }
            if (info.ReceiveUserId.IsNullEmpty())
            {
                return new NarutoFailResult("参数错误..");
            }
            if (info.pageIndex <= 0)
            {
                info.pageIndex = 1;
            }
            if (info.pageSize <= 0)
            {
                info.pageSize = 10;
            }
            var res = await chatMessageRepository.GetMyChatMessage(info.UserId, info.ReceiveUserId, info.pageIndex, info.pageSize) ?? new List<Entitys.VM.GetMyChatMessageViewModel>();
            return new NarutoSuccessResult("操作成功", res.OrderBy(a => a.CreateTime).ToList());
        }
    }
}
